package cn.wolfcode.wolf2w.job;

import cn.wolfcode.wolf2w.redis.service.IStrategyStatisVORedisService;
import cn.wolfcode.wolf2w.redis.vo.StrategyStatisVO;
import cn.wolfcode.wolf2w.service.IStrategyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Redis数据持久化
 *
 */
@Component
public class RedisDataPermanentJob {

    @Autowired
    private IStrategyService strategyService;

    @Autowired
    private IStrategyStatisVORedisService strategyStatisVORedisService;

    @Scheduled(cron = "0 0 12 * * ?")
    public void dowork() {
        System.out.println("-------------vo数据持久化--start--------------------");

        //获取redis中所有vo对象
        List<StrategyStatisVO> vos = strategyStatisVORedisService.queryStrategyVOListByParameter("*");

        //遍历集合更新MongoDB数据库
        for (StrategyStatisVO vo : vos) {
            strategyService.updateStrategyStatisDataByStrategyVO(vo);
        }

        System.out.println("-------------vo数据持久化--end--------------------");
    }

}
